// import { resolve } from 'path';
// import { axios } from 'axios';
export default {
  ssr: true,
  mode: 'spa', // default: universal | spa
  // Target: https://go.nuxtjs.dev/config-target
  target: 'static',
  loading: {
    color: '#4771DC',
    height: '2px'
  },
  router: {
    base: process.env.NODE_ENV === 'production' ? '/' : '/',
    mode: 'hash', // default: history | hash
    fallback: true,
    prefetchPayloads: true, // default: true
    middleware: ['auth', 'device'],
    // extendRoutes (routes) {
    //   routes.push({
    //     name: 'custom',
    //     path: '*',
    //     component: resolve(__dirname, 'layouts/error.vue')
    //   })
    // }
  },
  generate: {
    fallback: false,
    subFolders: false, // default: true | false
    // routes() {
    //   return axios.get('https://my-api/users').then(res => {
    //     console.log(res);
    //     return res.data.map(user => {
    //       console.log(user);
    //       return '/users/' + user.id
    //     })
    //   })
    // }
  },
  server: {
    host: 'localhost', // default: localhost
    port: 8100 // default: 3000
  },
  dev: process.env.NODE_ENV !== 'production',
  // Global page headers: https://go.nuxtjs.dev/config-head
  head: {
    title: '未来校招 - 大学生找工作、找实习',
    htmlAttrs: {
      'data-theme': 'light'
    },
    meta: [{
        charset: 'utf-8'
      },
      {
        name: 'viewport',
        content: 'width=device-width, initial-scale=1'
      },
      {
        hid: 'description',
        name: 'description',
        content: ''
      },
      {
        'http-equiv': 'X-UA-Compatible', content: 'IE=edge'
      },
    ],
    link: [{
      rel: 'icon',
      type: 'image/x-icon',
      href: '/favicon.ico'
    }]
  },

  // Global CSS: https://go.nuxtjs.dev/config-css
  css: [
    // 'element-ui/lib/theme-chalk/index.css',
    '@/assets/css/element-variables.scss',
    'swiper/dist/css/swiper.css',
    '@/assets/fonts/iconfont.css',
    '@/assets/css/reset.scss',
    '@/assets/css/main.scss'
  ],

  // Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
  plugins: [{
      src: '@/plugins/element-ui',
      ssr: false,
      mode: 'client'
    },
    {
      src: '@/plugins/vue-swiper.js',
      ssr: false,
      mode: 'client'
    },
    {
      src: '@/plugins/request.js',
      ssr: false,
    },
    {
      src: '@/plugins/directive.client.js',
      ssr: false,
      mode: 'client'
    },
    // {
    // src: '@/plugins/poly.js',
    // ssr: true
    // },
  ],

  // Auto import components: https://go.nuxtjs.dev/config-components
  components: true,

  // Modules for dev and build : https://go.nuxtjs.dev/config-modules
  buildModules: [
    // https://go.nuxtjs.dev/eslint
    '@nuxtjs/eslint-module',
    '@nuxtjs/style-resources',
  ],

  // Modules: https://go.nuxtjs.dev/config-modules
  modules: [
    // https://go.nuxtjs.dev/axios
    '@nuxtjs/axios',
    '@nuxtjs/proxy',
    // https://go.nuxtjs.dev/content
    '@nuxt/content',
  ],

  // Axios module configuration: https://go.nuxtjs.dev/config-axios
  // axios: {
  // baseURL: 'http://localhost:8100/api',
  // proxy: true, // 表示开启代理
  // prefix: '/api', // 表示给请求url加个前缀 /api
  // credentials: true // 表示跨域请求时是否需要使用凭证
  // },
  proxy: {
    '/apis': {
      target: 'http://apis.weilaixiaozhao.com/', // 目标接口域名
      // target: 'http://zpapi.fooce.cn/', // 目标接口域名
      pathRewrite: {
        '^/apis': '', // 把 /api 替换成 /
        changeOrigin: true // 表示是否跨域
      }
    },
    '/api': {
      target: 'http://apis.weilaixiaozhao.com/', // 目标接口域名
      // target: 'http://zpapi.fooce.cn/', // 目标接口域名
      pathRewrite: {
        '^/api': '', // 把 /api 替换成 /
        changeOrigin: true // 表示是否跨域
      }
    }
  },

  // Content module configuration: https://go.nuxtjs.dev/config-content
  content: {},

  styleResources: {
    // scss: './assets/css/_theme.scss',
    scss: './assets/css/variables.scss',
    // hoistUseStatements: true
  },

  // Build Configuration: https://go.nuxtjs.dev/config-build
  build: {
    transpile: [/^element-ui/],
    // 开启打包分析
    // analyze: true,
    // assetFilter (assetFilename) {
    // return assetFilename.endsWith('.js');
    // },
    // maxChunkSize: 300000,
    babel: { // 配置按需引入规则
      // babelrc: false,
      // cacheDirectory: undefined,
      // presets({ isServer }) {
      //   const targets = isServer ? { node: '10' } : { ie: '11' }
      //   return [[require.resolve('@nuxt/babel-preset-app'), { targets }]]
      // },
      plugins: [
        [
          'component',
          {
            libraryName: 'element-ui',
            styleLibraryName: 'theme-chalk'
          }
        ]
      ]
    },
    /*
     ** Run ESLINT on save
     */
    extend(config, ctx) {
      if (ctx.isClient) {
        config.module.rules.push({
          enforce: 'pre',
          test: /\.(js|vue)$/,
          loader: 'eslint-loader',
          exclude: /(node_modules)/
        })
      }
    },
  }
}
